<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">

          <a-col :md="8" :sm="24">
            <a-form-item label="采购单号">
              <a-input v-model="queryParam.orderNumber" placeholder="请输入采购单号"/>
            </a-form-item>
          </a-col>

          <a-col :md="!advanced && 8 || 24" :sm="24">
            <span class="table-page-search-submitButtons" :style="advanced && { float: 'right', overflow: 'hidden' } || {} ">
              <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
              <!--<a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>-->
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <s-table
      ref="table"
      size="default"
      :columns="columns"
      :data="loadData"
      :alert="true"
      :rowKey="(record) => record.code"
    >

      <span slot="action" slot-scope="text, record">
        <!-- <a @click="$refs.purchaseDetail.show(record, null, {materialType})">发货明细</a> -->
				<a @click="$refs.detailForm1.rukuDetails(record,
					{ materialType })">入库明细</a>
				<a-divider type="vertical" />
				<a @click="$refs.rukuList.show(record,
					{ materialType, orderType })">入库记录</a>
      </span>

    </s-table>

    <!--  订单明细  -->
    <purchase-detail ref="purchaseDetail"/>
		<detail-form1 ref="detailForm1" />
		<ruku-list ref="rukuList" />
  </a-card>
</template>

<script>
import {STable} from '@/components'
import {page} from '@/api/modular/main/emsorder/emsOrderManage'

import PurchaseDetail from './purchaseDetail'
import detailForm1 from '../../../materialManagement/purchaseOrderByWaitInStore/detailForm1'
import rukuList from '../../../materialManagement/purchaseOrderByWaitInStore/rukuList'

export default {
  components: {
    STable,
    PurchaseDetail,
		detailForm1,
		rukuList
  },
  data() {
    return {
      advanced: false, // 高级搜索 展开/关闭
      queryParam: {time:''},  // 查询参数
      columns: [
        {
          title: '序号', width:'80px',
          customRender: (text, record, index) => `${index + 1}`
        },
        {
          title: '采购单号',
          dataIndex: 'orderNumber'
        },
        {
          title: '供应商',
          dataIndex: 'targetOrgName'
        },
        // {
        //   title: '采购数量',
        //   dataIndex: '',
        //   customRender: (text, record, index) => `【没算】`
        // },
        // {
        //   title: '已发数量',
        //   dataIndex: '',
        //   customRender: (text, record, index) => `【没算】`
        // },
        {
          title: '采购时间',
          dataIndex: 'createTime'
        },
        {
          title: '入库完成时间',
          dataIndex: 'inStoreCompletedTime'
        },
        {
          title: '操作',
          dataIndex: 'action',
          width: '250px',
          scopedSlots: {customRender: 'action'}
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        this.queryParam.materialType = this.materialType
        this.queryParam.orderType = this.orderType
        if(this.$route.params.year && this.$route.params.mounth){
          this.queryParam.time = this.$route.params.year + '-' + this.$route.params.mounth
        }else{
          this.queryParam.time = ''
        }
        // 该页面需要查询两个状态的订单
        this.queryParam.executeStatuses = this.executeStatus.join(',')
        return page(Object.assign(parameter, this.queryParam)).then((res) => {
          return res.data
        })
      },
      scheduleProductionVisible: false,
      selectedRowKeys: [],
      selectedRows: [],
      defaultExpandedKeys: [],
      replaceFields: {
        key: 'id',
      },
    }
  },
  computed: {
    materialType() {
      return this.$businessEnum.MATERIAL_TYPE_ENUM.packing.id
    },
    orderType() {
      return this.$businessEnum.ORDER_TYPE_ENUM.purchaseOrder.id
    },
    executeStatus() {
      return [this.$businessEnum.EXECUTE_STATUS_ENUM.IN_STORE_COMPLETED.id, this.$businessEnum.EXECUTE_STATUS_ENUM.COMPLETED.id]
    },
  },
  created() {
  },
  methods: {
    handleOk() {
      this.$refs.table.refresh()
    },
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
  }
}
</script>